package com.user.controller;

import com.common.domain.entity.ResponseResult;
import com.common.domain.entity.User;
import com.common.enums.AppHttpCodeEnum;
import com.common.exception.SystemException;
import com.common.service.LoginServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 
 **/
@RestController
public class LoginController {
    @Autowired
    private LoginServer loginServer;

    @PostMapping("/login")
    public ResponseResult login(@RequestBody User user, HttpServletRequest request){
        if(!StringUtils.hasText(user.getUserName())){
            throw new SystemException(AppHttpCodeEnum.REQUIRE_USERNAME);
        }
        return loginServer.login(user);
    }

    @PostMapping("/logout")
    public ResponseResult logout(){
        return loginServer.logout();
    }
}
